enyo.kind({
    name: "MyApps.StoreDetail",
    kind: enyo.VFlexBox,
    events: {
        onBack: "",
    },
    
    components: [    /**
     * Services
     */
    {
        name: "getData",
        kind: "WebService",
        onSuccess: "gotData",
        onFailure: "gotDataFailure"
    }, {
        name: "pane",
        kind: "Pane",
        flex: 1,
        className: "storedetail",
        components: [{
            kind: "VFlexBox",
            flex: 1,
            components: [{
                kind: "PageHeader",
                className: "enyo-header-dark",
                components: [{
                    kind: "IconButton",
                    onclick: "doBack",
                    icon: "images/menu-icon-back.png",
                    className: "enyo-button-dark"
                }, {
                    name: "view",
                    kind: "VFlexBox",
                    flex: 1,
                    align: "center",
                    components: [{
                        name: "titleViewDetails",
                        content: "Magasin"
                    }, ]
                }, {
                    kind: "Button",
                    onclick: "showOnMap",
                    caption: "Carte",
                    className: "enyo-button-dark"
                }, ]
            }, {
                kind: "Scroller",
                flex: 1,
                components: [{
                
                    kind: "VFlexBox",
                    flex: 1,
                    components: [{
                        kind: "Group",
                        components: [{
                            kind: "HFlexBox",
                            align: "center",
                            style: "padding: 5px",
                            components: [{
                                name: "storeName",
                                flex: 1,
                            }, {
                                name: "storePhoto",
                                kind: "Image"
                            }]
                        }, ]
                    }, {
                        kind: "RowGroup",
                        caption: "Adresse",
                        components: [{
                            name: "adresse"
                        }, {
                            name: "adresse2"
                        }, ]
                    }, {
                        kind: "RowGroup",
                        caption: "Contact",
                        components: [{
                            name: "tel"
                        }, {
                            name: "mail"
                        }, ]
                    }, {
                        kind: "Group",
                        caption: "Horaires",
                        components: [{
                            name: "hourly",
                        }]
                    }, {
                        kind: "Group",
                        caption: "accès",
                        components: [{
                            name: "access",
                        }]
                    }, {
                        kind: "Group",
                        caption: "Responsable Magasin",
                        components: [{
                            kind: "HFlexBox",
                            align: "center",
                            style: "padding: 5px",
                            components: [{
                                name: "bossName",
                                flex: 1,
                            }, {
                                name: "bossPhoto",
                                kind: "Image"
                            }]
                        }, ]
                    }, ]
                }, ]
            }, ]
        }, {
            name: "mapView",
            kind: "MyApps.PointOnMap",
            onBack: "goBack",
            lazy: true,
        }, ]
    }, ],
    create: function(){
        this.inherited(arguments);
        this.store;
    },
    
    gotData: function(inSender, inResponse){
        this.store = inResponse;
        
        this.$.storeName.setContent(this.store.shop.nom);
        this.$.storePhoto.setSrc("http://golfplus.mobile2you.fr/images/shops/" + this.store.shop.shop_picture);
        
        this.$.adresse.setContent(this.store.shop.adresse);
        this.$.adresse2.setContent(this.store.shop.cp + " " + this.store.shop.ville + ", " + this.store.shop.pays);
        this.$.tel.setContent("Tel: " + this.store.shop.tel);
        this.$.mail.setContent("Email: " + this.store.shop.mail);
        
        this.$.hourly.setContent(this.store.shop.horaires);
        this.$.access.setContent(this.store.shop.acces);
        
        this.$.bossName.setContent(this.store.shop.bossName);
        this.$.bossPhoto.setSrc("http://golfplus.mobile2you.fr/images/shops/boss/" + this.store.shop.boss_picture);
        
    },
    gotDataFailure: function(inSender, inResponse){
        console.log("get Data failure");
    },
    
    setStoreId: function(storeid){
        this.$.getData.setUrl("http://golfplus.mobile2you.fr/shops/" + storeid + ".json");
        this.$.getData.call();
        this.$.view.render();
    },
    showOnMap: function(){
        this.$.pane.selectViewByName("mapView");
        this.$.mapView.showOnMap(this.store.shop.latitude, this.store.shop.longitude, this.store.shop.nom);
    },
    goBack: function(inSender, inEvent){
        this.$.pane.back(inEvent);
    },
})
